package it.polimi.traveldream.web;

import it.polimi.traveldream.GestioneRicercaLocal;
import it.polimi.traveldream.PackageDTO;

import java.util.Map;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;



@ManagedBean(name="infoPacchettoAdminBean")
@SessionScoped
public class InfoPacchettoAdminBean {
	
	
	@EJB
	private GestioneRicercaLocal gs;
	
	private String id; // id per la ricerca
    private PackageDTO packagebyid;
           
    public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public PackageDTO getPackagebyid() {
		return packagebyid;
	}

	public void setPackagebyid(PackageDTO packagebyid) {
		this.packagebyid = packagebyid;
	}
	
	
	public String outcome(){
 
		FacesContext fc = FacesContext.getCurrentInstance();
	    
		this.packagebyid = gs.ricercaPacchettoById(Integer.parseInt(getIdParam(fc)));
		System.out.print(" Nome pacchetto selezionato:"+ packagebyid.getNome());
		
		return "infoPacchettoAdmin.xhtml?faces-redirect=true";
		
		
	 }
 

	private String getIdParam(FacesContext fc){
 
	    Map<String,String> params = fc.getExternalContext().getRequestParameterMap();
		return params.get("action");
	}

}
